<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
      <!--BEGIN TITLE & BREADCRUMB PAGE-->
      <div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
          <div class="page-header pull-left">
              <div class="page-title">知识发布</div>
          </div>
          <ol class="breadcrumb page-breadcrumb pull-left">
              <li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li>知识库管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li class="active">知识发布</li>
          </ol>
           
          <div class="clearfix"></div>
      </div>
      <!--END TITLE & BREADCRUMB PAGE-->
      <!--BEGIN CONTENT-->
      <div class="page-content">
      
      <div class="row">
		      <div class="col-lg-12">
		       <div class="note note-danger">
		           <h3 class="box-heading">使用须知</h3>
		           <p>
		           	管理员新建知识发布任务后确认无误后提交，然后在分布式任务调度系统配置具体任务信息，启动任务即可完成知识发布操作。</a>
		           </p>
		       </div>
		   </div>
		</div>
      
      <div class="row mbl">
           <div class="col-lg-6">
               <div class="input-group input-group-sm mbs"><span class="input-group-btn">
                 <select id="queryParams" class="btn btn-danger dropdown-toggle" style="width :100px;">
                	<!-- <option value="">筛选项</option> -->
                		<option value="name">知识发布名称</option>
                		<option value="description">知识发布描述</option>
                </select>
               <!-- 	<button type="button" data-toggle="dropdown" class="btn btn-danger dropdown-toggle">筛选项&nbsp;<span class="caret"></span>
                   </button>
                   <ul class="dropdown-menu">
                       <li><a href="#"><i class="fa fa-tint"></i>&nbsp;知识库名称</a>
                       </li>
                       <li><a href="#"><i class="fa fa-money"></i>&nbsp;状态</a>
                       </li>
                   </ul> -->
                   </span>
                   <input id="electText" type="text" placeholder="请输入关键词..." class="form-control" /><span class="input-group-btn"><button type="button" data-toggle="dropdown" onclick="tabulate()" class="btn btn-success dropdown-toggle">搜索</button></span>
               </div>
           </div>
           <div class="col-lg-6">
               <div class="tb-group-actions pull-right"><span>当前共<label id="pageSize"></label>条记录</span>&nbsp;&nbsp;&nbsp;
                  <!--  <select class="table-group-action-input form-control input-inline input-small input-sm mlm">
                       <option value="">选择可操作项...</option>
                       <option value="Cancel">立即发布</option>
                       <option value="Cancel">取消发布</option>
                   </select>&nbsp;
                   <button class="btn btn-sm btn-primary"><i class="fa fa-check"></i>&nbsp; 提交
                   </button> -->
                   <button class="btn btn-sm btn-primary" onclick="submitForm()">新增
                   </button>
               </div>
           </div>
       </div>
      <table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
            <thead>
                <tr>
                    <!-- <th width="3%">
                        <input type="checkbox" class="checkall" />
                    </th> -->
                    <th style='text-align:center'>任务ID</th>
                    <th style='text-align:center'>知识发布名称</th>
                    <th style='text-align:center'>知识发布描述</th>
                    <th style='text-align:center'>知识库名称</th>
                    <th style='text-align:center'>是否增量更新</th>
                    <th style='text-align:center'>创建部门</th>
                    <th style='text-align:center'>创建日期</th>
                    <th width="7%" style='text-align:center'>状态</th>
                    <th width="12%" style='text-align:center'>可操作</th>
                </tr>
            </thead>
            <tbody id="text">
              <!--  <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>1</td>
                    <td>2016-8-5 疾病知识库发布</td>
                    <td>疾病知识库</td>
                    <td>2016-8-5 18:40:26</td>
                    <td>admin</td>
                    <td>0/15000</td>
                    <td><span class="label label-sm label-success">待发布</span>
                    </td>
                    <td>
                        <button type="button" class="btn btn-default btn-xs">立即发布</button>
                        <button type="button" class="btn btn-default btn-xs">取消发布</button>
                    </td>
                </tr>
                 <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>2</td>
                    <td>2016-8-5 疾病知识库发布</td>
                    <td>疾病知识库</td>
                    <td>2016-8-5 18:40:26</td>
                    <td>admin</td>
                    <td>0/15000</td>
                    <td><span class="label label-sm label-success">待发布</span>
                    </td>
                    <td>
                        <button type="button" class="btn btn-default btn-xs">立即发布</button>
                        <button type="button" class="btn btn-default btn-xs">取消发布</button>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>3</td>
                    <td>2016-8-5 疾病知识库发布</td>
                    <td>疾病知识库</td>
                    <td>2016-8-5 18:40:26</td>
                    <td>admin</td>
                    <td>0/15000</td>
                    <td><span class="label label-sm label-success">待发布</span>
                    </td>
                    <td>
                        <button type="button" class="btn btn-default btn-xs">立即发布</button>
                        <button type="button" class="btn btn-default btn-xs">取消发布</button>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>4</td>
                    <td>2016-8-5 疾病知识库发布</td>
                    <td>疾病知识库</td>
                    <td>2016-8-5 18:40:26</td>
                    <td>admin</td>
                    <td>0/15000</td>
                    <td><span class="label label-sm label-success">待发布</span>
                    </td>
                    <td>
                        <button type="button" class="btn btn-default btn-xs">立即发布</button>
                        <button type="button" class="btn btn-default btn-xs">取消发布</button>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>5</td>
                    <td>2016-8-5 疾病知识库发布</td>
                    <td>疾病知识库</td>
                    <td>2016-8-5 18:40:26</td>
                    <td>admin</td>
                    <td>0/15000</td>
                    <td><span class="label label-sm label-success">待发布</span>
                    </td>
                    <td>
                        <button type="button" class="btn btn-default btn-xs">立即发布</button>
                        <button type="button" class="btn btn-default btn-xs">取消发布</button>
                    </td>
                </tr>  -->
            </tbody>
        </table>
        	<div id="dataNull" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
		</div>
        <div id="page1" style="text-align: center; margin-top: 20px;"></div>
    </div>
                     
    <!--END CONTENT-->
    </div>
    
  
<?} ?>
<script>

//发布
function release(classesEn,id) {
	if (confirm("是否确认提交！！")) { 
 		$.ajax({
			type : "post",
			url : "knowledge-edit-data-submit-release.html",
			dataType : "json",
			data:{
				"classesEn":  classesEn,
				"id":  id
			},
    		
			success:function(res) {
					layer.msg('提交成功!');
					get();
				}
			});
	}
}

function detele(id) { 
if (confirm("是否确认删除！！")) {
	location.href="knowledge-edit-data-submit-detele.html?id="+id;
	layer.msg('删除成功!');
	} 
}



function submitForm() {
				layer.open({
				    type : 2,
				     icon: 1,
                    skin: 'layer-ext-moon',
					area : [ '600px', '550px' ],
					fix : false, //不固定
					scrollbar : false,
					shadeClose : true,
					move : false,
					skin : 'layui-layer-rim', //加上边框
					btn : [ '保存 ', '关闭' ],
					content :[ "knowledge-edit-data-submit-form.html",'no'],
					yes: function(index,layer){
    	                  var iframeWin = parent.window[layer.find('iframe')[0]['name']];
    	                  iframeWin.save();
    	                  get();
    	              },
					cancel : function(index) {
					}
				});
			}
		
		
		//
		
 var curr;
	$(function(){
  	 	 curr=1;
		tabulate(curr);
	});
function get(){
  tabulate(curr);
}
function tabulate(curr) {
 $.ajax({
			type : "post",
			url : "knowledge-edit-data-submit-list.html",
			dataType : "json",
			data:{
				"page":  curr || 1  ,
				"electText":$("#electText").val(),
				"queryParams":$("#queryParams").val()
			},
    		
			success:function(res) {
					//此处仅仅是为了演示变化的内容
					//alert(JSON.stringify(res));
					var str = "";
					$("#text").html("");
					if(res[0].dataSubmitList != "" ){
							$("#dataNull").hide();
						}else{
						$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
						document.getElementById('pageSize').innerHTML=0;
						}
					for ( var i = 0; i < res.length; i++) {
						for(var j = 0; j < res[i].dataSubmitList.length; j++ ){
						//alert(res[i].dataSubmitList[j].isIncrementIndex);
             		  	var typeList;
						if (res[i].dataSubmitList[j].isIncrementIndex == 0) {
							typeList = "否";
						}else if(res[i].dataSubmitList[j].isIncrementIndex == 1) {
							typeList = "是";
						}
						var classesZh='' ;
						var classesEn='';
						for(var k=0; k<res[i].classesList.length; k++){
						var nums =res[i].dataSubmitList[j].classesIds.split(";");
						for(var s=0; s<nums.length; s++){
							if(res[i].classesList[k].id == nums[s]){
								classesZh+=res[i].classesList[k].nameZh+";";
								classesEn+=res[i].classesList[k].nameEn+";";
							}
							}
						}
						
						var createUserName ;
						for(var k=0; k<res[i].departmentList.length; k++){
							if(res[i].departmentList[k].id == res[i].dataSubmitList[j].createUserId){
								createUserName=res[i].departmentList[k].name;
							}
						}
						str += "<tr>";
             		  	/* str+="<td><input type='checkbox'/></td>"; */
		           		str+="<td  style='text-align:center'>"+res[i].dataSubmitList[j].id+"</td>";
		           		str+="<td  style='text-align:center'>"+res[i].dataSubmitList[j].name+"</td>"; 
		           		str+="<td  style='text-align:center'>"+res[i].dataSubmitList[j].description+"</td>"; 
		           		str+="<td  style='width:300px;text-align:center'>"+classesZh+"</td>";
		           		str+="<td  style='text-align:center'>"+typeList+"</td>";
		           		str+="<td  style='text-align:center'>"+createUserName+"</td>"; 
		           		str+="<td  style='text-align:center'>"+res[i].dataSubmitList[j].createTime+"</td>";
		           		if(res[i].dataSubmitList[j].status==0){
		           			str+="<td style='text-align:center'><span class='label label-sm label-success'>未提交</span></td>";
		           		}else if(res[i].dataSubmitList[j].status==1){
		           			str+="<td style='text-align:center'><span class='label label-sm label-success'>已提交</span></td>";
		           		}else if(res[i].dataSubmitList[j].status==2){
		           			str+="<td style='text-align:center'><span class='label label-sm label-success'>任务执行中</span></td>";
		           		}else if(res[i].dataSubmitList[j].status==3){
		           			str+="<td style='text-align:center'><span class='label label-sm label-success'>任务执行结束</span></td>";
		           		}else if(res[i].dataSubmitList[j].status==-1){
		           			str+="<td style='text-align:center'><span class='label label-sm label-success'>任务执行错误</span></td>";
		           		}
		           			str+="<td  style='text-align:center'>";
		           		if(res[i].dataSubmitList[j].status==0){
		               		str +="<button type='button' class='btn btn-default btn-xs' onclick=\"release('"+ classesEn+ "','"+res[i].dataSubmitList[j].id+"')\">提交</button>";
		               }
		                str+=" <button type='button' class='btn btn-default btn-xs' onclick=\"detele('"+ res[i].dataSubmitList[j].id+ "')\">删除</button>";
		            	str+="</td>";
		        		str+="</tr>";
		        		
		        		document.getElementById('pageSize').innerHTML=res[i].dataSubmitList.length;
						}
					}
					$("#text").append(str); 
					
					
					laypage({
						cont : document.getElementById('page1'), //容器。值支持id名、原生dom对象，jquery对象,
						pages : res[0].count, //总页数
						skip : true, //是否开启跳页
						skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
						curr : curr || 1,
						last: res[0].count,
						groups : 6,//连续显示分页数
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								(obj.curr);
								curr = obj.curr;
							}
						}
					});
				
				}
			});
		}
		

			
</script>